package com.baifc.datasource;

import com.baifc.entity.Spitter;
import com.baifc.entity.Spittle;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * projectName: spring-in-action-web
 * packageName: com.baifc.datasource
 * Created: 2019/5/9.
 * Auther: baifc
 * Description:
 */
@Component
public class SpittleRepositoryImpl implements SpittleRepository {
    @Override
    public List<Spittle> findSpittles(long max, int count) {

        return createSpittles(count);
    }

    @Override
    public void save(Spitter spitter) {
        System.out.println("save spitter");
    }

    private List<Spittle> createSpittles(int count) {
        List<Spittle> spittles = new ArrayList<>();

        for (int i = 0; i < count; i ++) {
            spittles.add(new Spittle(Long.parseLong(String.valueOf(i)), "Spittle" + i, new Date(), Double.parseDouble("0." + i), Double.parseDouble("0." + i)));
        }
        return spittles;
    }
}
